﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Common;

namespace ETL.Business.Handlers.SessionHandler
{
    public class SetSessionProject
    {
        private SessionHelper sessionHelper = null;
        public SetSessionProject()
        {
            sessionHelper = new SessionHelper();
        }

        public virtual void Execute(string activity)
        {
            var crnt = sessionHelper.GetValue(Constants.SessionVars.CurrentProjectId);
            var last = sessionHelper.GetValue(Constants.SessionVars.LastProjectId);

            // last, crnt = blank
            if (string.IsNullOrEmpty(last) && string.IsNullOrEmpty(crnt))
            {
                sessionHelper.SetValue(Constants.SessionVars.CurrentProjectId, activity);
            }
            // last = blank, crnt != blank
            else if (string.IsNullOrEmpty(last) && !string.IsNullOrEmpty(crnt))
            {
                sessionHelper.SetValue(Constants.SessionVars.LastProjectId, crnt);
                sessionHelper.SetValue(Constants.SessionVars.CurrentProjectId, activity);
            }
            // last != blank, crnt = blank
            else
            {
                sessionHelper.SetValue(Constants.SessionVars.CurrentProjectId, activity);
            }
        }
    }
}
